﻿/*
Copyright (c) 2009, Luke Berndt
All rights reserved.
 
 * More Information: http://www.tagflo.com

Redistribution and use in source and binary forms, with or without modification, are permitted 
provided that the following conditions are met:

* Redistributions of source code must retain the above copyright notice, this list of conditions 
  and the following disclaimer.

* Redistributions in binary form must reproduce the above copyright notice, this list of conditions 
  and the following disclaimer in the documentation and/or other materials provided with the distribution.

* Neither the name of RoboTastic Software nor the names of its contributors may be used to endorse or 
  promote products derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED 
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A 
PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR 
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED 
TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 
POSSIBILITY OF SUCH DAMAGE.
*/


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Data.SqlServerCe;
using System.Data.OleDb;
using System.Data.SqlClient;
using System.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace TagFlo.Views
{
    /// <summary>
    /// Interaction logic for SelectionPanelItem.xaml
    /// </summary>
    public partial class SelectionPanelItem : TreeViewItem
    {
        public SelectionPanelItem()
        {
            InitializeComponent();
        }
       
        private String _header;
        private Uri   iconUri;
        private BitmapImage imageSource;

        public string HeaderText
        {
            get
            {
                return _header;
            }
        }



        public void UpdateItem()
        {
            Items.Refresh();
        }


        private void BuildTreeItem()
        {
            //Image itemImage = (Image) ItemTemplate.FindName("ItemImage", this);
            
           /* Binding SqlSelectBinding = new Binding();

            SqlSelectBinding.Source = treeItemDataTable;
            SqlSelectBinding.Mode = BindingMode.OneWay;
            this.SetBinding(TreeView.ItemsSourceProperty, SqlSelectBinding);


            Binding binding = new Binding();
            binding.Path = new PropertyPath(treeItemDataTable.Columns[0].ColumnName);
            binding.Mode = BindingMode.OneWay;
            */

            switch (_header)
            {
                case "Rating":

                    //binding.Converter = new RatingConverter();
                    iconUri = new Uri(@"pack://application:,,,/Icons/star.png", UriKind.Absolute);
                    break;
                case "IsoSpeed":
                   // binding.Converter = new IsoSpeedConverter();
                    iconUri = new Uri(@"pack://application:,,,/Icons/picture.png", UriKind.Absolute);
                    break;
                case "ExposureTime":
                    //binding.Converter = new ExposureTimeConverter();
                    iconUri = new Uri(@"pack://application:,,,/Icons/picture.png", UriKind.Absolute);
                    break;
                case "ExposureMode":
                    //binding.Converter = new ExposureModeConverter();
                    iconUri = new Uri(@"pack://application:,,,/Icons/picture.png", UriKind.Absolute);
                    break;
                case "LensAperture":
                    //binding.Converter = new LensApertureConverter();
                    iconUri = new Uri(@"pack://application:,,,/Icons/picture.png", UriKind.Absolute);
                    break;
                case "FocalLength":
                    //binding.Converter = new FocalLengthConverter();
                    iconUri = new Uri(@"pack://application:,,,/Icons/picture.png", UriKind.Absolute);
                    break;
                case "WhiteBalanceMode":
                    //binding.Converter = new WhiteBalanceConverter();
                    iconUri = new Uri(@"pack://application:,,,/Icons/picture.png", UriKind.Absolute);
                    break;
                case "CameraModel":
                    iconUri = new Uri(@"pack://application:,,,/Icons/camera.png", UriKind.Absolute);
                    break;
                case "Tag":
                    iconUri = new Uri(@"pack://application:,,,/Icons/tag_blue.png", UriKind.Absolute);
                    break;
                case "PhotoSetName":
                    iconUri = new Uri(@"pack://application:,,,/Icons/folder_image.png", UriKind.Absolute);
                    break;
                case "SmartSetName":
                    iconUri = new Uri(@"pack://application:,,,/Icons/folder_lightbulb.png", UriKind.Absolute);
                    break;
             
  

                default:
                    iconUri = new Uri(@"pack://application:,,,/Icons/picture.png", UriKind.Absolute);
                    break;
            }

FrameworkElementFactory dockElement = new FrameworkElementFactory(typeof(DockPanel));
            
            FrameworkElementFactory textElement = new FrameworkElementFactory(typeof(TextBlock));
            textElement.SetValue(TextBlock.ForegroundProperty, Brushes.Blue);
            //textElement.SetBinding(TextBlock.TextProperty, binding);


          

                      

            
         imageSource = new BitmapImage();
                                    imageSource.BeginInit();
                                    imageSource.UriSource = iconUri;
                                   imageSource.EndInit();
                                   imageSource.Freeze();
                                                           
            FrameworkElementFactory imageElement = new FrameworkElementFactory(typeof(Image));
          
        imageElement.SetValue(Image.SourceProperty, imageSource);
        imageElement.SetValue(Image.MarginProperty, new Thickness(0, 0, 5, 0));

            dockElement.AppendChild(imageElement);
            dockElement.AppendChild(textElement);
            DataTemplate dataTemplate = new DataTemplate();
            dataTemplate.VisualTree = dockElement;

            this.ItemTemplate = dataTemplate;
        }

        public SelectionPanelItem(String header, Uri uri)
            : base()
        {
            DockPanel dockPanel = new DockPanel();
            TextBlock textBlock = new TextBlock();
            Image image = new Image();
            _header = header;
            iconUri = uri;
            //BuildTreeItem();

            //this.Name = header + "SelectionPanelItem";
           // treeItemDataTable = new DataTable("TreeItemTable");


            imageSource = new BitmapImage();
            imageSource.BeginInit();
            imageSource.UriSource = iconUri;
            imageSource.EndInit();
            imageSource.Freeze();
            image.Source = imageSource;
            image.Margin = new Thickness(0, 0, 5, 0);
            textBlock.Text = header;
            dockPanel.Children.Add(image);
            dockPanel.Children.Add(textBlock);
            this.Header = dockPanel;
        }
    }
}

